﻿using System.Collections.Generic;
using CfgMusic;
using com.m3sdk.common;
using CSUtils;
using G02.SceneConfig;
using GlobalTripleJump;
using m3sdk;
using TripleJump;
using U3dGame;
using U3dUtils;
using UI00;
using UnityEngine;
using UnityEngine.UI;

namespace G02.TripleJump.UI {
    public class UI_GameRuning : UIBase {
        public static string prefabPath;

        protected override string _GetUIPrefabPath() {
            if (prefabPath != null) {
                return prefabPath;
            }
            return "TripleJump/UI/UI_GameRuning/UI_GameRuning.prefab";
        }

        protected override EUIType _uiType => EUIType.e04_main;
        public static Transform parent;

        protected override Transform _GetUIParent() {
            if (parent != null) {
                return parent;
            }
            return UIBase.uiLayer3_ui;
        }

        public static UI_GameRuning instance;

        public static void Open() {
            UIManage.Open<UI_GameRuning>();
        }

        RectTransform m_progressBarRt;
        public Image progress;
        Text textNull;

        protected override void _Init() {
            m_progressBarRt = m_rootRt.GetControl<RectTransform>("progressBar");
            progress = m_rootRt.GetControl<Image>("progressBar/progress");
            textNull = m_rootRt.GetControl<Text>("progressBar/textNull");
            m_progressBarRt.gameObject.SetActive(false);
            instance = this;
        }

        protected override void _Open(Dictionary<string, object> paraDic) {
            textNull.rectTransform.gameObject.SetActive(false);
            CMusicManage.PlayMusic(MusicCfg.button_positive);
            if (TripleJumpData.curr.gameCount > 0) {
                CDelayMain.Delay(1.2f).SetPauseEnd("").onCallback = delegate {
                    string ss = CL.G("o_ready"); //C_UIManage.GetInstance.uILanguage.UI_Scene.o_ready);

                    CDefEffectManage.PlayEffect(GlobalTripleJumpCfg.artPath_get_goldcoin, UI_Tips.GetInstance.tipsText.rectTransform.position);
                    UI_Tips.GetInstance.OpenTips(ss, true, true, false);

                    CDelayMain.Delay(1.1f).SetPauseEnd("").onCallback = delegate {
                        CDefEffectManage.PlayEffect(GlobalTripleJumpCfg.artPath_get_goldcoin, UI_Tips.GetInstance.tipsText.rectTransform.position);
                        ss = CL.G("o_go"); //C_UIManage.GetInstance.uILanguage.UI_Scene.o_go;
                        UI_Tips.GetInstance.OpenTips(ss, true, false, false);
                    };
                };
            }
        }

        protected override void _Close() {
            if (m_progressBarRt) {
                m_progressBarRt.gameObject.SetActive(false);
            }
        }

        /// <summary>
        /// 起跳质量提示
        /// </summary>
        public static void JumpQuality(int objId, int jumpCount, int accuracy) {
            if (TripleJump_FristRoleFly.CPara.firstRoleId != objId) {
                return;
            }
            //Debug.LogErrorFormat("起跳质量提示___{0}_____{1}_", jumpCount, accuracy);
            if (jumpCount < 4) {
                switch (accuracy) {
                    case 0:
                        CDefEffectManage.PlayEffect(GlobalTripleJumpCfg.artPath_get_goldcoin, UI_Tips.GetInstance.tipsText.rectTransform.position, 1);
                        string ss = CL.G("o_perfect"); //C_UIManage.GetInstance.uILanguage.UI_Scene.o_perfect);
                        UI_Tips.GetInstance.OpenTips(ss, true, false, true);
                        CMusicManage.PlayMusic(MusicCfg.PerfectJump);
                        CVibrator.OpenVibrator(0, 80);
                        break;
                    case 1:
                        CDefEffectManage.PlayEffect(GlobalTripleJumpCfg.artPath_get_goldcoin, UI_Tips.GetInstance.tipsText.rectTransform.position, 1);
                        ss = CL.G("o_great"); //C_UIManage.GetInstance.uILanguage.UI_Scene.o_great;
                        UI_Tips.GetInstance.OpenTips(ss, true, false, true);
                        CMusicManage.PlayMusic(MusicCfg.jump);
                        CVibrator.OpenVibrator(0, 80);
                        break;
                    case 2:
                        // CDefEffectManage.PlayEffect(CInt4.Get(-2, 16, 4, 0), UI_Tips.GetInstance.tipsText.rectTransform.position, 1);
                        ss = CL.G("o_ok"); //C_UIManage.GetInstance.uILanguage.UI_Scene.o_ok;
                        UI_Tips.GetInstance.OpenTips(ss, true, false, true);
                        CMusicManage.PlayMusic(MusicCfg.jump);
                        CVibrator.OpenVibrator(0, 50);
                        break;
                }
            }
            if (jumpCount == 3) {
                CDelayMain.Delay(0.5f).SetPauseEnd("").onCallback = delegate {
                    instance.m_progressBarRt?.SetActive(true);
                    instance.progress.fillAmount = 1;
                };
            } else if (jumpCount == 4) {
                instance.m_progressBarRt?.SetActive(false);
            }
        }

        public void EnergyProgress(int roleId, float currentEnergy, float totalEnergy) {
            if (TripleJump_FristRoleFly.CPara.firstRoleId != roleId) {
                return;
            }
            progress.fillAmount = currentEnergy / totalEnergy;
            if (currentEnergy < 0.1f) {
                textNull.rectTransform.gameObject.SetActive(true);
            }
        }
    }
}
